var ZYRequestClient = require("../../../../utils/zy-request");
var requestClient;
const app = getApp();
Page({
  data:{
    sealList:[],
    sealGroupList:[],
    navbarData:{
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '已删除印章', //导航栏 中间的标题
      white:true
     },
     // 导航头的高度
     height: app.globalData.height * 2 + 20
  },
  onLoad() {
    requestClient = new ZYRequestClient();
  },
  onShow(){
    var _this = this;
    _this.setData({
      sealList:[]
    });
    requestClient.checkFunctionPermission(1001,'您没有权限查看印章列表，请联系企业创建者！',function(){
      _this.loadSealList();
    },function(){
      wx.navigateBack({
        delta: 1,
      })
    });
  },
  // 加载印章列表
  loadSealList:function(){
    var _this = this;
    var deleteSealList = wx.getStorageSync('deleteSealList');
    _this.setData({
      sealList:deleteSealList
    });
    // 重组数据
    if(_this.data.sealList.length > 0){
      var sealList = _this.data.sealList;
      for(var i =0;i < sealList.length;i++){
        var seal = sealList[i];
        var departmentId = seal.departmentId;
        if(!_this.checkDuplicate(departmentId)){
          var sealGroupList = _this.data.sealGroupList;
          var sealGroup = {
            id:departmentId,
            name:departmentId == 0?'':seal.departmentVo.name
          };
          sealGroupList.push(sealGroup);
          _this.setData({
            sealGroupList:sealGroupList
          });
        }
      }
    }
  },
  // 判断是否重复
  checkDuplicate(departmentId){
    var _this = this;
    var sealGroupList = _this.data.sealGroupList;
    for(var i=0;i<sealGroupList.length;i++){
      var sealGroup = sealGroupList[i];
      if(sealGroup.id == departmentId){
        return true;
      }
    }
    return false;
  },
})